#include "../global.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Q_UNUSED(a);

    vtkCreate(reader, vtkDICOMImageReader);
    reader->SetDataByteOrderToLittleEndian();
    reader->SetDirectoryName(path.toStdString().c_str());
    reader->Update();

    vtkCreate(outline, vtkOutlineFilter);
    outline->SetInputConnection(reader->GetOutputPort());

    vtkCreate(outlineMapper, vtkPolyDataMapper);
    outlineMapper->SetInputConnection(outline->GetOutputPort());

    vtkCreate(outlineActor, vtkActor);
    outlineActor->SetMapper(outlineMapper);
    outlineActor->GetProperty()->SetOpacity(0);

    vtkCreate(renderer, vtkRenderer);
    vtkCreate(renWin, vtkRenderWindow);
    renWin->AddRenderer(renderer);
    vtkCreate(ireni, vtkRenderWindowInteractor);
    ireni->SetRenderWindow(renWin);

    vtkCreate(picker, vtkCellPicker);
    picker->SetTolerance(0.005);

    vtkCreate(ipwProp, vtkProperty);
    vtkCreate(planeWidgetX, vtkImagePlaneWidget);
    planeWidgetX->SetInteractor(ireni);
    planeWidgetX->SetKeyPressActivationValue('x');
    planeWidgetX->SetPicker(picker);
    planeWidgetX->GetPlaneProperty()->SetColor(0,1,0);
    planeWidgetX->SetTexturePlaneProperty(ipwProp);
    planeWidgetX->TextureInterpolateOn();
    planeWidgetX->SetResliceInterpolateToCubic();
    planeWidgetX->SetInputData(reader->GetOutput());
    planeWidgetX->SetPlaneOrientationToXAxes();
    planeWidgetX->SetSlicePosition(255);
    planeWidgetX->SetSliceIndex(125);
    planeWidgetX->DisplayTextOn();
    planeWidgetX->On();

    vtkCreate(planeWidgetY, vtkImagePlaneWidget);
    planeWidgetY->SetInteractor(ireni);
    planeWidgetY->SetKeyPressActivationValue('y');
    planeWidgetY->SetPicker(picker);
    planeWidgetY->GetPlaneProperty()->SetColor(0,1,0);
    planeWidgetY->SetTexturePlaneProperty(ipwProp);
    planeWidgetY->TextureInterpolateOn();
    planeWidgetY->SetResliceInterpolateToCubic();
    planeWidgetY->SetInputData(reader->GetOutput());
    planeWidgetY->SetPlaneOrientationToYAxes();
    planeWidgetY->SetSlicePosition(255);
    planeWidgetY->SetSliceIndex(125);
    planeWidgetY->DisplayTextOn();
    planeWidgetY->On();

    vtkCreate(planeWidgetZ, vtkImagePlaneWidget);
    planeWidgetZ->SetInteractor(ireni);
    planeWidgetZ->SetKeyPressActivationValue('z');
    planeWidgetZ->SetPicker(picker);
    planeWidgetZ->GetPlaneProperty()->SetColor(0,1,0);
    planeWidgetZ->SetTexturePlaneProperty(ipwProp);
    planeWidgetZ->TextureInterpolateOn();
    planeWidgetZ->SetResliceInterpolateToCubic();
    planeWidgetZ->SetInputData(reader->GetOutput());
    planeWidgetZ->SetPlaneOrientationToZAxes();
    planeWidgetZ->SetSlicePosition(255);
    planeWidgetZ->SetSliceIndex(125);
    planeWidgetZ->DisplayTextOn();
    planeWidgetZ->On();

    renderer->AddActor(outlineActor);
    renderer->SetBackground( 0.6, 0.6, 0.6);
    renWin->SetSize(600, 600);

    renderer->GetActiveCamera()->Elevation(110);
    renderer->GetActiveCamera()->SetViewUp(0, 0, -1);

    vtkCreate(tprop, vtkTextProperty);
    tprop-> SetColor(0, 0, 1);
    tprop-> ShadowOn();

    vtkCreate(axes, vtkCubeAxesActor2D);
    axes->SetInputData (outline-> GetOutput());
    axes->SetCamera (renderer-> GetActiveCamera());
//    axes-> SetLabelFormat("%6.4g");
    axes->SetFlyModeToOuterEdges();
    axes->SetFontFactor(0.8);
    axes->SetAxisTitleTextProperty(tprop);
    axes->SetAxisLabelTextProperty(tprop);
//    axes->GetProperty()->SetDiffuseColor(1, 0, 0.25);
    axes->SetFontFactor(6);

    renderer->AddViewProp(axes);
    renderer->GetActiveCamera()->Azimuth(45);
    renderer->GetActiveCamera()->Dolly(1.0);
    renderer->ResetCameraClippingRange();
    renderer->ResetCamera();
    renWin->Render();

    ireni->Initialize();
    ireni->Start();
    renWin->Render();

    return 0;
}
